home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
X User Tools
/
X User Tools (O'Reilly and Associates)(1994).ISO
/
sun4c
/
archive
/
tcltk.z
/
tcltk
/
man
/
cat3
/
CrtMathFnc.3
< prev
next >
Wrap
Text File
|
1994-09-20
|
5KB
|
133 lines
Tcl_CreateMathFunc(3)Tcl Library Procedures 7.0
_________________________________________________________________
NAME
Tcl_CreateMathFunc - Define a new math function for expres-
sions
SYNOPSIS
#include <tcl.h>
Tcl_CreateMathFunc(_i_n_t_e_r_p, _n_a_m_e, _n_u_m_A_r_g_s, _a_r_g_T_y_p_e_s, _p_r_o_c, _c_l_i_e_n_t_D_a_t_a)
ARGUMENTS
Tcl_Interp *_i_n_t_e_r_p (in) Interpreter in which
new function will be
defined.
char *_n_a_m_e (in) Name for new func-
tion.
int _n_u_m_A_r_g_s (in) Number of arguments
to new function;
also gives size of
_a_r_g_T_y_p_e_s array.
Tcl_ValueType *_a_r_g_T_y_p_e_s (in) Points to an array
giving the permissi-
ble types for each
argument to function.
Tcl_MathProc *_p_r_o_c (in) Procedure that imple-
ments the function.
ClientData _c_l_i_e_n_t_D_a_t_a (in) Arbitrary one-word
value to pass to _p_r_o_c
when it is invoked.
_________________________________________________________________
DESCRIPTION
Tcl allows a number of mathematical functions to be used in
expressions, such as sin, cos, and hypot.
Tcl_CreateMathFunc allows applications to add additional
functions to those already provided by Tcl or to replace
existing functions. _N_a_m_e is the name of the function as it
will appear in expressions. If _n_a_m_e doesn't already exist
as a function then a new function is created. If it does
exist, then the existing function is replaced. _N_u_m_A_r_g_s and
_a_r_g_T_y_p_e_s describe the arguments to the function. Each entry
in the _a_r_g_T_y_p_e_s array must be either TCL_INT, TCL_DOUBLE, or
TCL_EITHER to indicate whether the corresponding argument
must be an integer, a double-precision floating value, or
either, respectively.
Tcl 1
Tcl_CreateMathFunc(3)Tcl Library Procedures 7.0
Whenever the function is invoked in an expression Tcl will
invoke _p_r_o_c. _P_r_o_c should have arguments and result that
match the type Tcl_MathProc:
typedef int Tcl_MathProc(
ClientData _c_l_i_e_n_t_D_a_t_a,
Tcl_Interp *_i_n_t_e_r_p,
Tcl_Value *_a_r_g_s,
Tcl_Value *resultPtr);
When _p_r_o_c is invoked the _c_l_i_e_n_t_D_a_t_a and _i_n_t_e_r_p arguments
will be the same as those passed to Tcl_CreateMathFunc.
_A_r_g_s will point to an array of _n_u_m_A_r_g_s Tcl_Value structures,
which describe the actual arguments to the function:
typedef struct Tcl_Value {
Tcl_ValueType _t_y_p_e;
int _i_n_t_V_a_l_u_e;
double _d_o_u_b_l_e_V_a_l_u_e;
} Tcl_Value;
The _t_y_p_e field indicates the type of the argument and is
either TCL_INT or TCL_DOUBLE. It will match the _a_r_g_T_y_p_e_s
value specified for the function unless the _a_r_g_T_y_p_e_s value
was TCL_EITHER. Tcl converts the argument supplied in the
expression to the type requested in _a_r_g_T_y_p_e_s, if that is
necessary. Depending on the value of the _t_y_p_e field, the
_i_n_t_V_a_l_u_e or _d_o_u_b_l_e_V_a_l_u_e field will contain the actual value
of the argument.
_P_r_o_c should compute its result and store it either as an
integer in _r_e_s_u_l_t_P_t_r->_i_n_t_V_a_l_u_e or as a floating value in
_r_e_s_u_l_t_P_t_r->_d_o_u_b_l_e_V_a_l_u_e. It should set also _r_e_s_u_l_t_P_t_r->_t_y_p_e
to either TCL_INT or TCL_DOUBLE to indicate which value was
set. Under normal circumstances _p_r_o_c should return TCL_OK.
If an error occurs while executing the function, _p_r_o_c should
return TCL_ERROR and leave an error message in _i_n_t_e_r_p-
>_r_e_s_u_l_t.
KEYWORDS
expression, mathematical function
Tcl 2